package com.joekai.view_demo.utils;

import com.joekai.view_demo.BaseApplication;

/**
 * @author joekai
 */
public class PxUtils {
    private PxUtils(){

    }
    /**
     * 得到设备屏幕的宽度
     */
    public static int getScreenWidth() {
        return BaseApplication.getInstance().getResources().getDisplayMetrics().widthPixels;
    }

    /**
     * 得到设备屏幕的高度
     */
    public static int getScreenHeight() {
        return BaseApplication.getInstance().getResources().getDisplayMetrics().heightPixels;
    }
    /**
     * 得到设备的密度
     */
    public static float getScreenDensity() {
        return BaseApplication.getInstance().getResources().getDisplayMetrics().density;
    }

    /**
     * 将sp值转换为px值，保证文字大小不变
     *
     * @param spValue
     * @return
     */
    public static int sp2px(int spValue) {
        final float fontScale = BaseApplication.getInstance().getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }

    public static int dp2px(float dipValue) {
        final float scale = getScreenDensity();
        return (int) (dipValue * scale + 0.5);
    }
}
